package org.team102.frcscoutingapp;


import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.Toast;

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SuppressLint("NewApi")
public class MainMenu extends FragmentActivity {
	
	private  Spinner spinCompSelect;
	private Button btnSubmit;
	public final static String EXTRA_INITIALS = "org.example.frcscoutingapp.Initials";
	public final static String EXTRA_ALLIANCE = "org.example.frcscoutingapp.AllianceCol";
	public final static int COMPETITION_SELECTION = 0;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_menu);
		btnSubmit = (Button) findViewById(R.id.buttonStart);
		
		//stuff	
		addListenerOnButton();
		addListenerOnSpinnerItemSelection();
	}

	public void addListenerOnSpinnerItemSelection() {
		spinCompSelect = (Spinner) findViewById(R.id.spinnerCompSelect);
		spinCompSelect.setOnItemSelectedListener(new CustomOnItemSelectedListener());
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main_menu, menu);
		return true;
	}
	
	public void addListenerOnButton() {
		spinCompSelect = (Spinner)findViewById(R.id.spinnerCompSelect);
 
		btnSubmit.setOnClickListener(new View.OnClickListener() {
			@Override
			public  void  onClick (View v) {
				Toast.makeText(MainMenu.this, "You selected: " + String.valueOf(spinCompSelect.getSelectedItem()),Toast.LENGTH_SHORT).show();
			}
		});
	}
	
	/** Called when user clicks Start Button! */
	public void progStart(View view) {
		String alliance;
		Intent startIntent = new Intent(this, DisplayScouter.class);
		EditText initials = (EditText)findViewById(R.id.edit_Initials);
		RadioButton blueAlliance = (RadioButton)findViewById(R.id.radioBlue);
		if (blueAlliance.isChecked())
			alliance = "Blue";
		else
			alliance = "Red";
		String initial = initials.getText().toString();
		startIntent.putExtra(EXTRA_ALLIANCE, alliance);
		startIntent.putExtra(EXTRA_INITIALS, initial);
		startActivity(startIntent);
	}
}
